package cn.strive.eams.room.service.impl;

import cn.strive.eams.bus.pojo.entity.Bus;
import cn.strive.eams.room.mapper.RoomMapper;
import cn.strive.eams.room.pojo.dto.RoomQuery;
import cn.strive.eams.room.pojo.dto.RoomSaveParam;
import cn.strive.eams.room.pojo.entity.Room;
import cn.strive.eams.room.pojo.vo.RoomVO;
import cn.strive.eams.room.service.RoomService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
public class RoomServiceImpl implements RoomService {
    @Autowired
    RoomMapper roomMapper;

    @Override
    public void saveRoom(RoomSaveParam roomSaveParam) {
       log.debug("保存房间业务，参数{}",roomSaveParam);
        Room room = new Room();
        BeanUtils.copyProperties(roomSaveParam,room);
        if (room.getId() == null){//新增
            room.setCreateTime(new Date());
            log.debug("房间对象:{}",room);
            roomMapper.insert(room);
        }else {//更新
            room.setUpdateTime(new Date());
            roomMapper.update(room);
        }
    }

    @Override
    public List<RoomVO> selectAll(RoomQuery roomQuery) {
        log.debug("用户查询业务,参数:{}",roomQuery );
        return  roomMapper.selectAll(roomQuery);
    }

    @Override
    public void updateStatus(Long id, String status) {

            log.debug("更新房间状态:id={},status={}", id, status);
            Room room = new Room();
            room.setId(id);
            room.setStatus(status);
            roomMapper.update(room);

    }

    @Override
    public void deleteRoom(Long roomId) {
        log.debug("删除房间业务，参数:{}",roomId);
        roomMapper.deleteById(roomId);
    }
}
